
/**
 * concretefilters.cpp
 * 
 * This file implements all concrete filter classes
 * 
 * Copyright (c) 2008 Harunobu Oyama <nobukichi at gmail.com>
 * Licensed under GNU GPL version 3
 *
 */

#ifdef WIN32
#pragma warning( disable:4786 )
#endif

#include	"tweet.h"
#include	"concretefilters.h"

ShowAllFilter* ShowAllFilter::getInstance()
{
	static ShowAllFilter theInstance("show all");
	return &theInstance;
}

ShowAllFilter::ShowAllFilter(const QString& name)
  : Filter(name)
{
}

bool ShowAllFilter::test(const Tweet& tweet)
{
	Q_UNUSED(tweet);
	return true;
}

LatestUpdateFilter::LatestUpdateFilter(const QString& name)
  : Filter(name)
{
}

void LatestUpdateFilter::init()
{
	passedUsers.clear();
}

bool LatestUpdateFilter::test(const Tweet& tweet)
{
	if (passedUsers.find(tweet.userName()) == passedUsers.end()) {
		passedUsers.insert(tweet.userName());
		return true;
	}
	return false;
}

AtUserFilter::AtUserFilter(const QString& name, const QString& atUser)
  : Filter(name),
	atUserName(atUser) 
{
}

bool AtUserFilter::test(const Tweet& tweet)
{
	return (tweet.atUser() == atUserName);
}

UserFilter::UserFilter(const QString& name, const QString& user)
  : Filter(name),
	userName(user)
{
}

bool UserFilter::test(const Tweet& tweet)
{
	return (tweet.userName() == userName);
}

WhenFilter::WhenFilter(const QString& name, int secs)
  : Filter(name),
	seconds(secs)
{
}

bool WhenFilter::test(const Tweet& tweet)
{
	return (tweet.timeStamp().secsTo(QDateTime::currentDateTime()) < seconds);
}
	
